// -----------------------------------------------------------------------
//  <copyright file="OrganizationController.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/12/10 14:36:07</last-date>
// -----------------------------------------------------------------------

using DaprPlus.Identity.Application.Identity.Organizations.Commands;
using DaprPlus.Identity.Application.Identity.Organizations.Queries;


namespace DaprPlus.Identity.Api.Controllers;

[ApiResultWrapperFilter]
public class OrganizationController(IMediator mediator) : ApiControllerBase
{
    [HttpGet("{id}")]
    [Produces<OrganizationOutDto>]
    public async Task<ActionResult> Get(long id)
    {
        var query = new GetOrganizationByIdQuery(id);
        var result = await mediator.Send(query);
        if (result == null)
        {
            return NotFound();
        }
        return Ok(result);
    }

    [HttpPost("read")]
    [Produces<PageResult<OrganizationOutDto>>]
    public async Task<ActionResult> Read([FromBody] GetOrganizationPageQuery query)
    {
        var result = await mediator.Send(query);
        return Ok(result);
    }

    [HttpPost]
    [Produces<ApiResult>]
    public async Task<ActionResult> Create([FromBody] CreateOrganizationCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpPut]
    [Produces<ApiResult>]
    public async Task<ActionResult> Update([FromBody] UpdateOrganizationCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpDelete()]
    [Produces<ApiResult>]
    public async Task<ActionResult> Delete(long[] ids)
    {
        var command = new DeleteOrganizationCommand(ids);
        var result = await mediator.Send(command);
        return Ok(result);
    }
}
